package com.heima.apis.article;

import com.heima.apis.article.fallback.IArticleClientFallback;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;

@FeignClient(value = "leadnews-article", fallback = IArticleClientFallback.class)
public interface IArticleClient {

    @PostMapping("/api/v1/article/save")
    public ResponseResult saveArticle(@RequestBody ArticleDto dto) throws InvocationTargetException, IllegalAccessException;

    /**
     * 收藏或取消收藏文章
     * @param userId 用户ID
     * @param articleId 文章ID
     * @param isCollect 是否收藏 true-收藏 false-取消收藏
     * @return
     */
    @PostMapping("/api/v1/collection/collect")
    ResponseResult collectArticle(@RequestParam Integer userId,
                                  @RequestParam Long articleId,
                                  @RequestParam Boolean isCollect);

    /**
     * 判断文章是否被收藏
     * @param userId 用户ID
     * @param articleId 文章ID
     * @return
     */
    @GetMapping("/api/v1/collection/isCollected")
    public ResponseResult isArticleCollected(@RequestParam Integer userId,
                                             @RequestParam Long articleId);



    /**
     * 获取用户收藏文章列表
     * @param userId 用户ID
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @GetMapping("/api/v1/collection/userCollections")
    ResponseResult getUserCollections(@RequestParam Integer userId,
                                      @RequestParam Integer page,
                                      @RequestParam Integer size);

    /**
     * 点赞或取消点赞文章
     * @param userId 用户ID
     * @param articleId 文章ID
     * @param isLike 是否点赞 true-点赞 false-取消点赞
     * @return
     */
    @PostMapping("/api/v1/article/likes/like")
    ResponseResult likeArticle(@RequestParam Integer userId,
                               @RequestParam Long articleId,
                               @RequestParam Boolean isLike);

    /**
     * 判断文章是否被点赞
     * @param userId 用户ID
     * @param articleId 文章ID
     * @return
     */
    @GetMapping("/api/v1/article/likes/isLiked")
    ResponseResult isArticleLiked(@RequestParam Integer userId,
                                  @RequestParam Long articleId);

    /**
     * 获取用户点赞文章列表
     * @param userId 用户ID
     * @param page 页码
     * @param size 每页大小
     * @return
     */
    @GetMapping("/api/v1/article/likes/user/{userId}")
    ResponseResult getUserLikedArticles(@PathVariable Integer userId,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size);


}